# Maintainer: Sarah Ottinger

_realname=pytest-flake8
pkgbase=mingw-w64-python-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-python-${_realname}")
pkgver=1.0.7
pkgrel=2
pkgdesc='pytest plugin to check FLAKE8 requirements (mingw-w64)'
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64')
url="https://github.com/tholo/pytest-flake8"
license=('MIT')
depends=("${MINGW_PACKAGE_PREFIX}-python-pytest"
         "${MINGW_PACKAGE_PREFIX}-python-flake8")
makedepends=("${MINGW_PACKAGE_PREFIX}-python-setuptools")
source=("https://github.com/tholo/pytest-flake8/archive/$pkgver.tar.gz")
sha256sums=('db5b71e53408982b8973194e80cee2c8a38024d68eb2f7e9bd96207ed0223381')

prepare() {  
  cd "$srcdir"
  rm -rf python-build-${CARCH} | true
  cp -r "${_realname}-${pkgver}" "python-build-${CARCH}"
  sed -i 's/ignore = E128/ignore = E128 W605/' "python-build-${CARCH}/tox.ini"
}

build() {
  msg "Python build for ${CARCH}"  
  cd "${srcdir}/python-build-${CARCH}"
  ${MINGW_PREFIX}/bin/python setup.py build
}

check() {
  cd "${srcdir}/python-build-${CARCH}"
  ${MINGW_PREFIX}/bin/python setup.py install --root="$PWD/tmp_install" --optimize=1 || warning "Tests failed"
  PYTHONPATH="$PWD/${MINGW_PREFIX}/lib/python3.8/site-packages:$PYTHONPATH" ${MINGW_PREFIX}/bin/py.test || warning "Tests failed"
}

package() {
  cd "${srcdir}/python-build-${CARCH}"
  MSYS2_ARG_CONV_EXCL="--prefix=;--install-scripts=;--install-platlib=" \
  ${MINGW_PREFIX}/bin/python setup.py install --prefix=${MINGW_PREFIX} \
    --root="${pkgdir}" --optimize=1 --skip-build
  install -Dm644 LICENSE "${pkgdir}${MINGW_PREFIX}/share/licenses/python-${_realname}/LICENSE"
}
